import easyocr


class OCRModel:

    lang_dict = {
        '简体中文': 'ch_sim',
        '繁体中文': 'ch_tra',
        '英语': 'en',
        '日语': 'ja',
        '韩语': 'ko',
        '拉丁语': 'Latin',
        '俄语': 'ru',
        '德语': 'de',
        '法语': 'fr'
    }

    def __init__(self, source: bytes, **kwargs) -> None:
        self._source = source
        self._langs = [self.lang_dict.get(kwargs.get('lang'))] or ['ch_sim', 'en']
        self._reader = easyocr.Reader(lang_list=self._langs, gpu=False)

    def readtext(self) -> list:
        return self._reader.readtext(self._source, detail=0)


if __name__ == '__main__':
    with open('C:/Users/Fisher/Desktop/1.png', 'rb') as f:
        a = f.read()
    model = OCRModel(a, **{'lang': '简体中文'})
    res = model.readtext()
    print(res)
